﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using InfoJetSoft.Service.Entity;

//CID 0741 //2011.03.07 //Begin
namespace InfoJetSoft.Service.Worker
{
    class FormFormatPlaceholderTextWorker
    {
        private static char[] ruleSeparator = { ';' };
        private static char[] nameValueSeparator = { ':' };

        public static void formatPlaceholderText(Form form, XmlElement inputTextElement, string xdGhosted)
        {
            string ghosted = inputTextElement.GetAttribute(xdGhosted);
            if (ghosted.Equals("true"))
            {
                string style = inputTextElement.GetAttribute("style");
                if (style.Length > 0)
                {
                    string lowerStyle = style.ToLower();
                    if (lowerStyle.IndexOf("color") >= 0)
                    {
                        bool found = false;
                        string[] rules = lowerStyle.Split(ruleSeparator);
                        foreach (string rule in rules)
                        {
                            string[] nameValue = rule.Split(nameValueSeparator);
                            string name = nameValue[0].Trim();
                            if (name.Equals("color"))
                            {
                                found = true;
                                string color = nameValue[1].Trim().Replace(";", "");
                                inputTextElement.SetAttribute("noneghostedcolor", color);
                                break;
                            }
                        }
                        if (!found)
                        {
                            inputTextElement.SetAttribute("noneghostedcolor", "");
                        }
                    }
                    else
                    {
                        inputTextElement.SetAttribute("noneghostedcolor", "");
                    }
                }
                inputTextElement.SetAttribute("style", style + "; color:#a3a3a3;");
            }
        }
    }
}
//CID 0741 //2011.03.07 //End
